<@_survey id=id;survey>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>${survey.title!}</title>
    <meta name="description" content="${survey.description!}"/>
</head>
<body>
    <header>
        <h1>${(site.name)!}</h1>
    </header>
    <nav>
        <a href="${base}">Home</a>
<@_categoryList>
    <#list page.list as a>
        <a href="${a.url!}" target="_blank">${a.name}</a>
    </#list>
</@_categoryList>
    </nav>
    <main>
        <h1>${survey.title!}</h1>
        <p>${survey.description!}</p>
        <p>started on ${survey.startDate!},end on:${(survey.endDate)!}</p>
        <#assign available=false/>
        <#if survey.startDate lt .now && .now lt survey.endDate>
            <#assign available=true/>
        </#if>
        <p>server time : ${.now} <#if available>working</#if></p>
        <#macro message code>${springMacroRequestContext.getMessage(code)}</#macro>
        <#if user?has_content>
            <@_userSurvey userId=user.id surveyId=survey.id>
                <#assign available=false/>
                <p>You have already participated!</p>
            </@_userSurvey>
        <#else>
            <#assign available=false/>
            <p>Please <a href="${site.dynamicPath}login.html?returnUrl=${(site.dynamicPath+'survey.html?id='+survey.id)?url}">login</a></p>
        </#if>
        <form action="${site.dynamicPath}survey/save" method="POST">
            <input name="_csrf" type="hidden" value="<@_csrfToken/>"/>
            <input name="surveyId" type="hidden" value="${survey.id}"/>
            <input name="returnUrl" type="hidden" value="${site.dynamicPath}survey.html?id=${survey.id}"/>
            <ul>
        <@_surveyQuestionList surveyId=survey.id pageSize=500>
            <#list page.list as a>
                <li>
                    <h3>[<@message 'page.question.type.'+a.questionType/>] ${a.title!} <#if 'exam'=survey.surveyType>(${a.score!})</#if></h3>
                <#if a.cover?has_content>
                    <p>
                        <img src="${(a.cover)!}" alt="${a.title!}"/>
                    </p>
                </#if>
                    <p>
                        <input name="answerList[${a?index}].id.questionId" type="hidden" value="${a.id}">
                    <#switch a.questionType>
                        <#case 'radio'>
                            <@_surveyQuestionItemList questionId=a.id pageSize=500>
                                <#list page.list as i>
                                    <label><input name="answerList[${a?index}].answer" type="radio" value="${i.id}"<#if a?is_first> required="required"</#if><#if !available> disabled="true"</#if>/>${i.title}</label>
                                </#list>
                            </@_surveyQuestionItemList>
                        <#break>
                        <#case 'select'>
                            <@_surveyQuestionItemList questionId=a.id pageSize=500>
                                <select name="answerList[${a?index}].answer"<#if !available> disabled="true"</#if>>
                                    <#list page.list as i>
                                        <option value="${i.id}">${i.title}</option>
                                    </#list>
                                </select>
                            </@_surveyQuestionItemList>
                        <#break>
                        <#case 'checkbox'>
                            <@_surveyQuestionItemList questionId=a.id pageSize=500>
                                <#list page.list as i>
                                    <label><input name="answerList[${a?index}].answer" type="checkbox" value="${i.id}"<#if !available> disabled="true"</#if>/>${i.title}</label>
                                </#list>
                            </@_surveyQuestionItemList>
                        <#break>
                        <#case 'text'>
                            <textarea name="answerList[${a?index}].answer" maxlength="150" cols="80" rows="4" required="required"<#if !available> disabled="true"</#if>></textarea>
                        <#break>
                        <#case 'file'>
                            <input name="answerList[${a?index}].answer" type="text" maxlength="150" required="required" placeholder="file URL"<#if !available> disabled="true"</#if>/>
                        <#break>
                        <#case 'picture'>
                            <input name="answerList[${a?index}].answer" type="text" maxlength="150" required="required" placeholder="picture URL"<#if !available> disabled="true"</#if>/>
                        <#break>
                    </#switch>
                    </p>
                </li>
            </#list>
        </@_surveyQuestionList>
            </ul>
            <p><input type="submit" value="Submit"<#if !available> disabled="true"</#if>/></p>
        </form>
    </main>
    <footer>
        Copyright &copy; ${.now?string('yyyy')}
    </footer>
    <script>
    var itemString="itemType=survey&itemId=${survey.id}";
    </script>
    
    <script src="${site.dynamicPath!}resource/js/jquery-1.12.4.min.js"></script>
    <script src="${site.dynamicPath}resource/js/cms.analytics.js"></script>
    <script>
        var ca = cmsAnalytics();
        var url='${site.dynamicPath}api/visit/record';
        if("string" ==typeof itemString){
            url=url+"?"+itemString;
        }
        ca.setDomain('${domain.name}');
        ca.setPath('/');
        ca.report(url);
    </script>
</body>
</html>
</@_survey>